package com.gambi.tapestry.client.gwtui.widgets;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent;
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler;
import com.google.gwt.user.client.ui.FormPanel.SubmitEvent;
import com.google.gwt.user.client.ui.FormPanel.SubmitHandler;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.SubmitButton;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class LoginFormWidget extends Composite {

	private HorizontalPanel horizontalPanel = new HorizontalPanel();

	public LoginFormWidget(String id, String url) {

		final FormPanel form = new FormPanel();
		form.setMethod(FormPanel.METHOD_POST);
		form.setAction(url);

		VerticalPanel holder = new VerticalPanel();

		holder.add(new Label("User ID"));
		TextBox userid = new TextBox();
		userid.setName("userid");
		holder.add(userid);

		holder.add(new Label("Password"));
		PasswordTextBox passwd = new PasswordTextBox();
		passwd.setName("passwd");
		holder.add(passwd);

		holder.add( new SubmitButton("Submit"));
		
		form.add(holder);
		
		form.addSubmitCompleteHandler(new SubmitCompleteHandler() {
			@Override
			public void onSubmitComplete(SubmitCompleteEvent event) {
				Window.alert("Submitted Completed");
				GWT.log(event.toString());
				GWT.log( event.getResults());
			}
		});

		form.addSubmitHandler(new SubmitHandler() {

			@Override
			public void onSubmit(SubmitEvent event) {
				Window.alert("Submitted");
				GWT.log(event.toString());
			}
		});
		initWidget(form);
	}
}
